use "data\out\pre_patterns_sample.dta", clear 

fmerge m:1 maalepktnr using "data\out\estsample_maalepktnr.dta", keep(match) nogen 

keep if (year == 2019 & month < 12)
g byte IHD = inlist(stratgroups,2,5,8,11) == 1

g consumption_all = forbruk
g consumption_0_15 = forbruk if inrange(hour,0,15) 
g consumption_16_21 = forbruk if inrange(hour,16,21) 
g consumption_22_23 = forbruk if inrange(hour,22,23)

fmerge m:1 maalepktnr using "data\in\maalepktnr_grunnkretsincome.dta", keep(master match) nogenerate
g income = Snittprhusstand / 9.5377 

/0*
foreach y of varlist cons* IHD income {
	g sd_`y' = `y'
} 
gcollapse (mean) cons* IHD income (sd) sd_*, by(elcar)
*/

    estpost su consumption* elcar IHD income if Treat == 1 & noncomplier == 0 
	est store Complier
    estpost su consumption* elcar  IHD income if Treat == 1 & noncomplier == 1 
	est store NonComplier
    estpost su consumption* elcar IHD income if Treat == 0 
	est store Control
	//gunique maalepktnr if elcar == `i'
	//estadd scalar Nhh = `r(N)'
esttab Complier NonComplier Control using "output\table_A1.txt", cells("mean (fmt(2)) sd (fmt(2) par)") varwidth(17) mtitles tex replace

gunique maalepktnr if Treat == 1 & noncomplier == 0
gunique maalepktnr if Treat == 1 & noncomplier == 1
gunique maalepktnr if Treat == 0

  
